package com.wenson.creational.factory;

import java.util.Random;

/**
 * @author: luowangcheng
 * @data：2024/6/10 17:51
 * @description:
 */
public class SimpleFactory {
    private int screenWidth;
    private Random random; // 随机数

    public SimpleFactory(int screenWidth) {
        this.screenWidth = screenWidth;
        this.random = new Random();
    }

    public Enemy create(String type) {
        int x = random.nextInt(screenWidth); // 横坐标
        Enemy enemy = null;
        switch (type) {
            case "Airplane": {
                enemy = new Airplane(x, 0);
                break;
            }
            case "Tank": {
                enemy = new Tank(x, 0);
                break;
            }
        }
        return enemy;
    }
}
